package br.com.primeira.scenes.gamescenes;

import org.andengine.entity.scene.background.Background;
import org.andengine.entity.sprite.Sprite;

import br.com.primeira.activities.GameActivity;
import br.com.primeira.activities.GameActivity.SceneType;
import br.com.primeira.scenes.GameScene;

public class SplashScene extends GameScene
{
	private float timer;
	
	public SplashScene(GameActivity gameActivity)
	{
		super(gameActivity);
		
		timer = 0f;
		
		setBackground(new Background(1f, 1f, 1f));
		
		Sprite splash = new Sprite(0, 0, assetPool.getTextureRegion("splash"), gameActivity.getEngine().getVertexBufferObjectManager());
		splash.setPosition((gameActivity.getEngine().getCamera().getWidth() - splash.getWidth()) * 0.5f,
						   (gameActivity.getEngine().getCamera().getHeight() - splash.getHeight()) * 0.5f);
		
		attachChild(splash);
	}
	
	@Override
	protected void onManagedUpdate(float pSecondsElapsed)
	{
		super.onManagedUpdate(pSecondsElapsed);
		
		timer += pSecondsElapsed;
		
		if(timer > 3.0f)
		{
			detachChildren();
			detachSelf();
			gameActivity.setScene(SceneType.GAME);
		}
	}
}
